/**
 * StudentQuestionService.java
 * Version 1.0.0
 * Created on 2018年9月14日
 *
 */
package com.yincheng.oes.business.exam.studentquest.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yincheng.oes.business.exam.studentquest.entity.StudentQuestion;
import com.yincheng.oes.business.exam.studentquest.mapper.StudentQuestionMapper;
import com.yincheng.oes.sso.util.UserUtils;

/**
 * @author yangsy
 * @version 1.0.0
 * @since
 * 创建时间：2018年9月14日
 * <p>
 * 功能描述：
 * <p>
 * 邮箱地址：446948434@qq.com
 */
@Service
public class StudentQuestionService {

    @Autowired
    private StudentQuestionMapper studentQuestionMapper;

    public void createStudentQuestion(StudentQuestion bean) {
        StudentQuestion param = new StudentQuestion();
        param.setBookClass(bean.getBookClass());
        param.setBookSubject(bean.getBookSubject());
        param.setQuesCode(bean.getQuesCode());
        param.setUserId(bean.getUserId());
        param.setValid("1");
        StudentQuestion question = studentQuestionMapper.selectByParam(param);
        if (question == null) {
            bean.setCreateTime(new Date());
            bean.setValid("1");
            studentQuestionMapper.insert(bean);
        }

    }

    @Transactional
    public void createStudentQuestion(List<StudentQuestion> beans) {
        String userId = UserUtils.getUser().getUserId();
        beans.forEach(e -> {
            e.setUserId(userId);
            createStudentQuestion(e);
        });
    }

}
